package start;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class Java8Compare {
    public static void main(String[] args) {
        // 假设List中存储了MyObject对象，其中包含可能为空的Date类型的日期字段
        List<MyObject> myObjects = new ArrayList<>();
        myObjects.add(new MyObject("Object1", null));
        myObjects.add(new MyObject("Object2", new Date(1626796800000L))); // 2021-07-20 00:00:00
        myObjects.add(new MyObject("Object3", new Date(1577836800000L))); // 2020-01-01 00:00:00

        // 使用Comparator对List中的MyObject对象按照可能为空的Date类型的日期字段进行降序排序，空值放在最后

        myObjects.sort(Comparator.comparing(MyObject::getDate, Comparator.nullsLast(Date::compareTo)));

        //myObjects.stream()
        //        .sorted(Comparator.comparing(MyObject::getDate, Comparator.nullsFirst(Comparator.reverseOrder())))
        //        .collect(Collectors.toList());

        // 打印排序后的MyObject对象
        for (MyObject obj : myObjects) {
            System.out.println(obj.getName() + " - " + obj.getDate());
        }

        List<OaClass> oaClasses = new ArrayList<>();
        OaClass oaClass01 = new OaClass();
        oaClass01.setFdId("18d1f4762acaf9768f74ec84b9da7788");
        oaClass01.setSubject("徐辉提交的合同审查流程");
        oaClass01.setNum("20240119001");
        oaClass01.setCreater("徐辉");
        oaClass01.setStatus("30");


        OaClass oaClass02 = new OaClass();
        oaClass02.setFdId("18f02ef10657d736cdc59ba47188a234");
        oaClass02.setSubject("孙晓东提交的合同审查流程");
        oaClass02.setNum("20240422001");
        oaClass02.setCreater("孙晓东");
        oaClass02.setStatus("30");

        OaClass oaClass03 = new OaClass();
        oaClass03.setFdId("192ac8b5d824c60ab1b487a4b309c8c1");
        oaClass03.setSubject("石家庄分公司区块业务三部招待费核销");
        oaClass03.setNum("分公司申请〔2024〕第422001号");
        oaClass03.setCreater("宫政");
        oaClass03.setStatus("30");

        oaClasses.add(oaClass01);
        oaClasses.add(oaClass02);
        oaClasses.add(oaClass03);

        Collections.sort(oaClasses, Comparator.comparing(OaClass::getCreater).reversed());
        oaClasses.sort(Comparator.comparing(OaClass::getNum, Comparator.nullsLast(String::compareTo)).reversed());

        System.out.println(oaClasses.get(0).getNum());
    }
}

class MyObject {
    private String name;
    private Date date;

    public MyObject(String name, Date date) {
        this.name = name;
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public Date getDate() {
        return date;
    }
}



class OaClass {

    private String fdId;
    private String subject;
    private String num;
    private String creater;
    private String status;

    public String getFdId() {
        return fdId;
    }

    public void setFdId(String fdId) {
        this.fdId = fdId;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}


